<script setup>
import { Head } from '@inertiajs/vue3'
import { computed } from 'vue'
import SpotlightLayout from '@/Layouts/SpotlightLayout.vue'
import Container from '@/Components/Spotlight/Container.vue'
import Prose from '@/Components/Spotlight/Prose.vue'
import SocialLink from '@/Components/Spotlight/SocialLink.vue'
import { XIcon, InstagramIcon, GitHubIcon, LinkedInIcon } from '@/Components/Spotlight/SocialIcons.js'
import LinkIcon from '@/Components/Spotlight/icons/LinkIcon.vue'
import PageHero from '@/Components/Spotlight/PageHero.vue'

const props = defineProps({
  about: {
    type: Object,
    required: true,
  },
})

const iconMap = {
  x: XIcon,
  twitter: XIcon,
  instagram: InstagramIcon,
  github: GitHubIcon,
  linkedin: LinkedInIcon,
}

const socialLinks = computed(() => {
  if (!Array.isArray(props.about.social_links)) {
    return []
  }

  return props.about.social_links.map((link) => ({
    ...link,
    iconComponent: iconMap[link.icon?.toLowerCase?.()] || LinkIcon,
  }))
})

const skills = computed(() => props.about.skills || [])
</script>

<template>
  <SpotlightLayout :title="`关于 - ${about.name}`">
    <Head :title="`关于 - ${about.name}`" />

    <Container class="mt-16 sm:mt-24">
      <PageHero
        :title="about.name"
        :description="about.bio"
        maxWidth="max-w-2xl"
      />
    </Container>

    <Container class="mt-16 sm:mt-24">
      <div class="grid gap-16 lg:grid-cols-[minmax(0,320px)_minmax(0,1fr)]">
        <div class="space-y-10 text-sm leading-6 text-zinc-600 dark:text-zinc-400">
          <div class="space-y-2">
            <p v-if="about.location" class="font-medium text-zinc-900 dark:text-zinc-100">
              {{ about.location }}
            </p>
            <p v-if="about.email">
              <a :href="`mailto:${about.email}`" class="transition hover:text-primary-600 dark:hover:text-primary-400">
                {{ about.email }}
              </a>
            </p>
          </div>

          <div v-if="socialLinks.length" class="space-y-2">
            <h2 class="text-xs font-semibold uppercase tracking-[0.2em] text-zinc-400 dark:text-zinc-500">
              社交链接
            </h2>
            <ul class="space-y-1">
              <li v-for="link in socialLinks" :key="link.name">
                <SocialLink :href="link.url" :icon="link.iconComponent">
                  {{ link.name }}
                </SocialLink>
              </li>
            </ul>
          </div>

          <div v-if="skills.length" class="space-y-4">
            <h2 class="text-xs font-semibold uppercase tracking-[0.2em] text-zinc-400 dark:text-zinc-500">
              技能专长
            </h2>
            <div class="space-y-3">
              <div v-for="(skill, index) in skills" :key="index" class="space-y-1">
                <p class="font-medium text-zinc-900 dark:text-zinc-100">
                  {{ skill.name }}
                </p>
                <p class="text-sm text-zinc-600 dark:text-zinc-400">
                  {{ skill.description }}
                </p>
              </div>
            </div>
          </div>
        </div>

        <Prose class="prose-zinc">
          <div v-html="about.content"></div>
        </Prose>
      </div>
    </Container>
  </SpotlightLayout>
</template>
